package leetcode.dataStructure;


import org.junit.Test;

import java.util.*;
class Business implements Runnable {
    @Override
    public void run() {

    }
}
class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}

public class MyQueue  {

    @Test
    public void sea() {
        Map<Integer,Integer> map = new HashMap<>();
        Set<Integer> set = map.keySet();
        List<Integer> list = new LinkedList<>();
        List<Integer> res = new LinkedList<>(list);

    }




    @Test
    public void search() {
        int[] nums = {5,7,7,8,8,10};
        int target = 6;
        int l=0, r= nums.length-1;
        int len=0;
        while(l<=r){
            int mid = (r+l)/2;
            if(nums[mid]==target){
                System.out.println(bfs(nums, target, mid, len));
            }else if(nums[mid]<target)l=mid;
            else r = mid;
            if((l==mid||r==mid)&&nums[l]!=target)break;
        }
        System.out.println(0);
    }

    int bfs(int[] nums, int target, int mid, int len){
        int m = mid;
        while(mid>=0&&nums[mid]==target){
            mid--;
            len++;
        }

        while(m<nums.length&&nums[m+1]==target){
            m++;
            len++;
        }
        return len;
    }

    @Test
    public void addStrings() {
        String num1 = "";
        System.out.println(num1.length());



    }
    @Test
    public void reversePrint() {
        ListNode head = new ListNode(1);
        head.next = new ListNode(2);
        head.next.next = new ListNode(3);
        head.next.next.next = new ListNode(4);
        ListNode cur = head;
        List<Integer> list = new ArrayList<>();
        dfs(cur,list);
        Map<Integer,Integer> map = new HashMap<>();
        Set<Integer> set = map.keySet();

        int a = 5;
        double b = 5;
        System.out.println((double) 5);

    }
    boolean dfs(ListNode cur, List<Integer> list ){
        if(cur==null) return true;
        dfs(cur.next,list);
        
        list.add(cur.val);
        return true;
    }


    int[] a = new int[]{1,2,3};
    int[] b = a;


    @Test
    public void return2(){

            System.out.println(a==b);//输出false
            System.out.println(a.equals(b));//输出false
            System.out.println(Arrays.equals(a,b));//输出true
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }

    @Override
    public String toString() {
        return super.toString();
    }

    @Test
    public void return1(){
        String s = "leetcode";
        char[] arr = s.toCharArray();
        char[] arr1 = s.toCharArray();

        Set<Character> set = new HashSet<>();
        System.out.println(s.length());
        System.out.println(s.charAt(7));
        for (int i = 0; i < s.length(); i++) {
            if(!set.add(s.charAt(i))){
                System.out.println("NoNoNo");
            }
        }

        Map<Character, Integer> map = new HashMap<>();
        Set<Character> set1 = map.keySet();
    }


    public synchronized void return2(List<Integer> list3,  int[] arr3){
        int[] arr4 = new int[3];
        List<Integer> list4 = new ArrayList<>();
        arr4[0] = 1;
        arr4[1] = 1;
        arr4[2] = 1;
        arr3[0] = 1;
        arr3[1] = 12;
        arr3[2] = 1;
        list3.add(1);
        list3.add(1);
        list3.add(1);
        list3.add(1);
    }



    @Test
    //给一个实例
    public void test1() {

        Stack<Integer> s1 = new Stack<Integer>();
        Stack<Integer> s2 = new Stack<Integer>();
        s1.push(1);
        s2.push(2);
        System.out.println(s1);
        int p1 = s1.peek();
        int p2 = s2.peek();
        System.out.println(p1==p2);
        System.out.println(s1.peek() == s2.peek());
    }

    List<Integer> list1 = new LinkedList<>();
    List<Integer> list2 = new LinkedList<>();
    @Test
    public void test(){
        list1.add(1);
        list1.add(1);
        list1.add(2);
        MyQueue();
        pop();
        pop();
        pop();

        empty();
    }


    public int[] MyQueue() {
        int[] list = new int[list1.size()];
        for (int i = 0; i < list1.size(); i++) {
            list[i] = list1.get(i);
        }

        String s = Arrays.toString(list);
        System.out.println("list = "+s);
        return list;
    }

    public void push(int x) {
        list1.add(x);
    }

    public int pop() {
        int[] list = MyQueue();
        list2.clear();
        System.out.println(list[0]);
        for (int i = 1; i < list1.size(); i++) {
            list2.add(list1.get(i));
        }
        list1.clear();
        list1.addAll(list2);
        return list[0];
    }

    public int peek() {
        int[] list = MyQueue();
        System.out.println(list[0]);
        return list[0];
    }

    public boolean empty() {
        int[] list = MyQueue();
        if (list.length==0){
            System.out.println("true");
            return true;
        }else {
            System.out.println("false");
            return false;
        }
    }
}
